package com.pkk.penguin.uti.oss.util;

import com.pkk.penguin.uti.oss.constant.PenguinOssSysConstant;
import com.pkk.penguin.uti.oss.enums.FileTypeEnum;
import com.pkk.penguin.uti.oss.support.PenguinOssSupport;
import com.qcloud.cos.model.ObjectMetadata;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: oss上传工具类
 * @author: peikunkun
 * @create: 2019-11-08 11:51
 **/
@Slf4j
public class PenguinOssUploadUtil {

  /**
   * @Description: 上传本地文件
   * @Param: [localFilePath]
   * @return: boolean
   * @Author: peikunkun
   * @Date: 2019/11/8 0008 下午 1:59
   */
  public static String uploadFileLocal(String localFilePath) {
    String path = "";
    try {
      FileInputStream fileInputStream = new FileInputStream(localFilePath);
      path = PenguinOssSupport.uploadToTCOss(fileInputStream, PenguinOssSysConstant.PARENT_PATH_IMAGE
          , new ObjectMetadata(), FileTypeEnum.PNG.getFileType());
      log.info("保存文件路径:" + path);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    return path;
  }


}
